#version 460
#extension GL_GOOGLE_include_directive : enable
#define GLSLIFY 1

#define GLSLIFY 1
#define PROJECT_MATRIX

/*
0 投影矩阵
1 属性参数
2 变换数据
3 颜色数据

4 顶点数据
5 顶点配置参数


6 颜色控制参数

10 纹理数据

*/

layout(std140, set=0, binding=0) uniform U_Matrix {
	mat4 mat_ProjecView;
};

layout(std140, binding = 1) uniform U1_Matrix {
	//边界
	vec2 m_Scale;
	vec2 m_Loc;
	//顶点总数量一半
	int m_GradientNum;
	int vertNum;
};

// 位置  大小 缩放和深度
layout(std430, column_major, binding = 2) readonly buffer U2_Matrix {
	mat3x2 m_LP_SD[];
};

 

layout(location = 0) in vec2 inPos;
layout(location = 1) in vec2 inWeights;
layout(location = 2) in vec2 inNormal;

layout(location = 0) out vec2 vUV;
layout(location = 1) out flat uint gInstanceIndex;

 
void main(void) {
	vUV = inWeights;
	gInstanceIndex = gl_InstanceIndex;

	mat3x2 mat = m_LP_SD[gl_InstanceIndex];
	vec4 v = vec4(0.0, 0.0, 0.0, 1.0);

	mat2 rot;
	rot[0] = vec2(cos(mat[2].y), -sin(mat[2].y));
	rot[1] = vec2(sin(mat[2].y), cos(mat[2].y));

	v.xy = (inPos * mat[2].x) + ((mat[1]-mat[2].x) * inWeights.xy * rot);
	

	v.xy += mat[0];
	v.xy *= m_Scale;
	v.xy += m_Loc;
	
	v.xy = round(v.xy) + 0.5;
	//v.y = round(v.y) + 0.5;
	
	gl_Position = mat_ProjecView * v;
	//gl_PointSize = 4.0;
	
	
}

